package com.yuwei.smartpark
import android.Manifest
import android.os.Build
import android.os.CountDownTimer
import android.util.Log
import androidx.annotation.RequiresApi
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.yuwei.base.BaseActivity
import com.yuwei.base.BaseViewActivity
import com.yuwei.base.path.RouterPath
import com.yuwei.http.entity.AccessIdParam
import com.yuwei.smartpark.databinding.ActivitySplashBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SplashActivity : BaseActivity<ActivitySplashBinding,SplashViewModel>() {
    @RequiresApi(Build.VERSION_CODES.M)
    override fun initView() {
        val countDownTimer = object :CountDownTimer(5000,1000){
            override fun onTick(millisUntilFinished: Long) {
                binding.tvTime.text = "${millisUntilFinished/1000}s"
            }

            override fun onFinish() {
                ARouter.getInstance().build(RouterPath.MODULE_MAIN_ACTIVITY).navigation()
                finish()
            }
        }.start()
        binding.tvSkip.setOnClickListener {
            countDownTimer.cancel()
            ARouter.getInstance().build(RouterPath.MODULE_MAIN_ACTIVITY).navigation()
            finish()
        }
        val param = AccessIdParam(
            accessId = 0,
            appName = "智慧园区",
            bundleName = "com.yuwei.smartpark",
            description = "这是一个智慧园区项目",
            icon = "无",
            id = 0,
            typeName = "管理类"
        )
        vm.getAccessId(param)
        requestPermissions(arrayOf(
            Manifest.permission.ACCESS_COARSE_LOCATION ,
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE
        ),102)
    }

    override fun initData() {
        vm.getAccessIdSuccess.observe(this){
            ToastUtils.showLong("666")
        }
    }

}